home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / tcsh / dist / sh.time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-21  |  15.1 KB  |  614 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.01/RCS/sh.time.c,v 3.4 1991/11/26 04:41:23 christos Exp $ */
  2. /*
  3.  * sh.time.c: Shell time keeping and printing.
  4.  */
  5. /*-
  6.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Berkeley and its contributors.
  21.  * 4. Neither the name of the University nor the names of its contributors
  22.  *    may be used to endorse or promote products derived from this software
  23.  *    without specific prior written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35.  * SUCH DAMAGE.
  36.  */
  37. #include "sh.h"
  38.  
  39. RCSID("$Id: sh.time.c,v 3.4 1991/11/26 04:41:23 christos Exp $")
  40.  
  41. #if defined(sun) && ! defined(MACH)
  42. # include <machine/param.h>
  43. #endif /* sun */
  44.  
  45. /*
  46.  * C Shell - routines handling process timing and niceing
  47.  */
  48. #ifdef BSDTIMES
  49. # ifndef RUSAGE_SELF
  50. #  define    RUSAGE_SELF    0
  51. #  define    RUSAGE_CHILDREN    -1
  52. # endif    /* RUSAGE_SELF */
  53. #else /* BSDTIMES */
  54. struct tms times0;
  55. #endif /* BSDTIMES */
  56.  
  57. #if !defined(BSDTIMES) && !defined(_SEQUENT_)
  58. # ifdef POSIX
  59. static    void    pdtimet    __P((clock_t, clock_t));
  60. # else /* ! POSIX */
  61. static    void    pdtimet    __P((time_t, time_t));
  62. # endif /* ! POSIX */
  63. #else /* BSDTIMES || _SEQUENT_ */
  64. static    void    pdeltat    __P((timeval_t *, timeval_t *));
  65. #endif /* BSDTIMES || _SEQUENT_ */
  66.  
  67. void
  68. settimes()
  69. {
  70. #ifdef BSDTIMES
  71.     struct rusage ruch;
  72.  
  73.     (void) gettimeofday(&time0, NULL);
  74.     (void) getrusage(RUSAGE_SELF, &ru0);
  75.     (void) getrusage(RUSAGE_CHILDREN, &ruch);
  76.     ruadd(&ru0, &ruch);
  77. #else
  78. # ifdef _SEQUENT_
  79.     struct process_stats ruch;
  80.  
  81.     (void) get_process_stats(&time0, PS_SELF, &ru0, &ruch);
  82.     ruadd(&ru0, &ruch);
  83. # else    /* _SEQUENT_ */
  84.     time0 = times(×0);
  85.     times0.tms_stime += times0.tms_cstime;
  86.     times0.tms_utime += times0.tms_cutime;
  87.     times0.tms_cstime = 0;
  88.     times0.tms_cutime = 0;
  89. # endif    /* _SEQUENT_ */
  90. #endif /* BSDTIMES */
  91. }
  92.  
  93. /*
  94.  * dotime is only called if it is truly a builtin function and not a
  95.  * prefix to another command
  96.  */
  97. /*ARGSUSED*/
  98. void
  99. dotime(v, c)
  100.     Char **v;
  101.     struct command *c;
  102. {
  103. #ifdef BSDTIMES
  104.     timeval_t timedol;
  105.     struct rusage ru1, ruch;
  106.  
  107.     (void) getrusage(RUSAGE_SELF, &ru1);
  108.     (void) getrusage(RUSAGE_CHILDREN, &ruch);
  109.     ruadd(&ru1, &ruch);
  110.     (void) gettimeofday(&timedol, NULL);
  111.     prusage(&ru0, &ru1, &timedol, &time0);
  112. #else
  113. # ifdef _SEQUENT_
  114.     timeval_t timedol;
  115.     struct process_stats ru1, ruch;
  116.  
  117.     (void) get_process_stats(&timedol, PS_SELF, &ru1, &ruch);
  118.     ruadd(&ru1, &ruch);
  119.     prusage(&ru0, &ru1, &timedol, &time0);
  120. # else /* _SEQUENT_ */
  121. #  ifndef POSIX
  122.     time_t  timedol;
  123. #  else /* POSIX */
  124.     clock_t timedol;
  125. #  endif /* POSIX */
  126.  
  127.     struct tms times_dol;
  128.  
  129.     timedol = times(×_dol);
  130.     times_dol.tms_stime += times_dol.tms_cstime;
  131.     times_dol.tms_utime += times_dol.tms_cutime;
  132.     times_dol.tms_cstime = 0;
  133.     times_dol.tms_cutime = 0;
  134.     prusage(×0, ×_dol, timedol, time0);
  135. # endif    /* _SEQUENT_ */
  136. #endif /* BSDTIMES */
  137. }
  138.  
  139. /*
  140.  * donice is only called when it on the line by itself or with a +- value
  141.  */
  142. /*ARGSUSED*/
  143. void
  144. donice(v, c)
  145.     register Char **v;
  146.     struct command *c;
  147. {
  148.     register Char *cp;
  149.     int     nval = 0;
  150.  
  151.     v++, cp = *v++;
  152.     if (cp == 0)
  153.     nval = 4;
  154.     else if (*v == 0 && any("+-", cp[0]))
  155.     nval = getn(cp);
  156. #ifdef BSDNICE
  157.     (void) setpriority(PRIO_PROCESS, 0, nval);
  158. #else /* BSDNICE */
  159.     (void) nice(nval);
  160. #endif /* BSDNICE */
  161. }
  162.  
  163. #ifdef BSDTIMES
  164. void
  165. ruadd(ru, ru2)
  166.     register struct rusage *ru, *ru2;
  167. {
  168.     tvadd(&ru->ru_utime, &ru2->ru_utime);
  169.     tvadd(&ru->ru_stime, &ru2->ru_stime);
  170.     if (ru2->ru_maxrss > ru->ru_maxrss)
  171.     ru->ru_maxrss = ru2->ru_maxrss;
  172.  
  173.     ru->ru_ixrss += ru2->ru_ixrss;
  174.     ru->ru_idrss += ru2->ru_idrss;
  175.     ru->ru_isrss += ru2->ru_isrss;
  176.     ru->ru_minflt += ru2->ru_minflt;
  177.     ru->ru_majflt += ru2->ru_majflt;
  178.     ru->ru_nswap += ru2->ru_nswap;
  179.     ru->ru_inblock += ru2->ru_inblock;
  180.     ru->ru_oublock += ru2->ru_oublock;
  181.     ru->ru_msgsnd += ru2->ru_msgsnd;
  182.     ru->ru_msgrcv += ru2->ru_msgrcv;
  183.     ru->ru_nsignals += ru2->ru_nsignals;
  184.     ru->ru_nvcsw += ru2->ru_nvcsw;
  185.     ru->ru_nivcsw += ru2->ru_nivcsw;
  186. }
  187.  
  188. #else /* BSDTIMES */
  189. # ifdef _SEQUENT_
  190. void
  191. ruadd(ru, ru2)
  192.     register struct process_stats *ru, *ru2;
  193. {
  194.     tvadd(&ru->ps_utime, &ru2->ps_utime);
  195.     tvadd(&ru->ps_stime, &ru2->ps_stime);
  196.     if (ru2->ps_maxrss > ru->ps_maxrss)
  197.     ru->ps_maxrss = ru2->ps_maxrss;
  198.  
  199.     ru->ps_pagein += ru2->ps_pagein;
  200.     ru->ps_reclaim += ru2->ps_reclaim;
  201.     ru->ps_zerofill += ru2->ps_zerofill;
  202.     ru->ps_pffincr += ru2->ps_pffincr;
  203.     ru->ps_pffdecr += ru2->ps_pffdecr;
  204.     ru->ps_swap += ru2->ps_swap;
  205.     ru->ps_syscall += ru2->ps_syscall;
  206.     ru->ps_volcsw += ru2->ps_volcsw;
  207.     ru->ps_involcsw += ru2->ps_involcsw;
  208.     ru->ps_signal += ru2->ps_signal;
  209.     ru->ps_lread += ru2->ps_lread;
  210.     ru->ps_lwrite += ru2->ps_lwrite;
  211.     ru->ps_bread += ru2->ps_bread;
  212.     ru->ps_bwrite += ru2->ps_bwrite;
  213.     ru->ps_phread += ru2->ps_phread;
  214.     ru->ps_phwrite += ru2->ps_phwrite;
  215. }
  216.  
  217. # endif    /* _SEQUENT_ */
  218. #endif /* BSDTIMES */
  219.  
  220. #ifdef BSDTIMES
  221.  
  222. /*
  223.  * PWP: the LOG1024 and pagetok stuff taken from the top command,
  224.  * written by William LeFebvre
  225.  */
  226. /* Log base 2 of 1024 is 10 (2^10 == 1024) */
  227. #define LOG1024         10
  228.  
  229. /* Convert clicks (kernel pages) to kbytes ... */
  230. /* If there is no PGSHIFT defined, assume it is 11 */
  231. /* Is this needed for compatability with some old flavor of 4.2 or 4.1? */
  232. #ifndef PGSHIFT
  233. # define pagetok(size)   ((size) << 1)
  234. #else
  235. # if PGSHIFT>10
  236. #  define pagetok(size)   ((size) << (PGSHIFT - LOG1024))
  237. # else
  238. #  define pagetok(size)   ((size) >> (LOG1024 - PGSHIFT))
  239. # endif
  240. #endif
  241.  
  242. /*
  243.  * if any other machines return wierd values in the ru_i* stuff, put
  244.  * the adjusting macro here:
  245.  */
  246. #ifdef sun
  247. # define IADJUST(i)    (pagetok(i)/2)
  248. #else /* sun */
  249. # define IADJUST(i)    (i)
  250. #endif /* sun */
  251.  
  252. void
  253. prusage(r0, r1, e, b)
  254.     register struct rusage *r0, *r1;
  255.     timeval_t *e, *b;
  256.  
  257. #else /* BSDTIMES */
  258. # ifdef _SEQUENT_
  259. void
  260. prusage(r0, r1, e, b)
  261.     register struct process_stats *r0, *r1;
  262.     timeval_t *e, *b;
  263.  
  264. # else /* _SEQUENT_ */
  265. void
  266. prusage(bs, es, e, b)
  267.     struct tms *bs, *es;
  268.  
  269. #  ifndef POSIX
  270.     time_t  e, b;
  271.  
  272. #  else    /* POSIX */
  273.     clock_t e, b;
  274.  
  275. #  endif /* POSIX */
  276. # endif    /* _SEQUENT_ */
  277. #endif /* BSDTIMES */
  278. {
  279. #ifdef BSDTIMES
  280.     register time_t t =
  281.     (r1->ru_utime.tv_sec - r0->ru_utime.tv_sec) * 100 +
  282.     (r1->ru_utime.tv_usec - r0->ru_utime.tv_usec) / 10000 +
  283.     (r1->ru_stime.tv_sec - r0->ru_stime.tv_sec) * 100 +
  284.     (r1->ru_stime.tv_usec - r0->ru_stime.tv_usec) / 10000;
  285.  
  286. #else
  287. # ifdef _SEQUENT_
  288.     register time_t t =
  289.     (r1->ps_utime.tv_sec - r0->ps_utime.tv_sec) * 100 +
  290.     (r1->ps_utime.tv_usec - r0->ps_utime.tv_usec) / 10000 +
  291.     (r1->ps_stime.tv_sec - r0->ps_stime.tv_sec) * 100 +
  292.     (r1->ps_stime.tv_usec - r0->ps_stime.tv_usec) / 10000;
  293.  
  294. # else /* _SEQUENT_ */
  295. #  ifndef POSIX
  296.     register time_t t = (es->tms_utime - bs->tms_utime +
  297.              es->tms_stime - bs->tms_stime) * 100 / HZ;
  298.  
  299. #  else /* POSIX */
  300.     register clock_t t = (es->tms_utime - bs->tms_utime +
  301.               es->tms_stime - bs->tms_stime) * 100 / CLK_TCK;
  302.  
  303. #  endif /* POSIX */
  304. # endif /* _SEQUENT_ */
  305. #endif /* BSDTIMES */
  306.  
  307.     register char *cp;
  308.     register long i;
  309.     register struct varent *vp = adrof(STRtime);
  310.  
  311. #ifdef BSDTIMES
  312.     int     ms =
  313.     (e->tv_sec - b->tv_sec) * 100 + (e->tv_usec - b->tv_usec) / 10000;
  314.  
  315.     cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
  316. #else
  317. # ifdef _SEQUENT_
  318.     int     ms =
  319.     (e->tv_sec - b->tv_sec) * 100 + (e->tv_usec - b->tv_usec) / 10000;
  320.  
  321.     cp = "%Uu %Ss %E %P %I+%Oio %Fpf+%Ww";
  322. # else /* _SEQUENT_ */
  323. #  ifndef POSIX
  324.     time_t  ms = (e - b) * 100 / HZ;
  325.  
  326. #  else /* POSIX */
  327.     clock_t ms = (e - b) * 100 / CLK_TCK;
  328.  
  329. #  endif /* POSIX */
  330.     cp = "%Uu %Ss %E %P";
  331.  
  332.     /*
  333.      * the tms stuff is not very precise, so we fudge it.
  334.      * granularity fix: can't be more than 100% 
  335.      * this breaks in multi-processor systems...
  336.      * maybe I should take it out and let people see more then 100% 
  337.      * utilizations.
  338.      */
  339.     if (ms < t && ms != 0)
  340.     ms = t;
  341. # endif /* _SEQUENT_ */
  342. #endif /* BSDTIMES */
  343. #ifdef TDEBUG
  344.     xprintf("es->tms_utime %lu bs->tms_utime %lu\n",
  345.         es->tms_utime, bs->tms_utime);
  346.     xprintf("es->tms_stime %lu bs->tms_stime %lu\n",
  347.         es->tms_stime, bs->tms_stime);
  348.     xprintf("ms %lu e %lu b %lu\n", ms, e, b);
  349.     xprintf("t %lu\n", t);
  350. #endif /* TDEBUG */
  351.  
  352.     if (vp && vp->vec[0] && vp->vec[1])
  353.     cp = short2str(vp->vec[1]);
  354.     for (; *cp; cp++)
  355.     if (*cp != '%')
  356.         xputchar(*cp);
  357.     else if (cp[1])
  358.         switch (*++cp) {
  359.  
  360.         case 'U':        /* user CPU time used */
  361. #ifdef BSDTIMES
  362.         pdeltat(&r1->ru_utime, &r0->ru_utime);
  363. #else
  364. # ifdef _SEQUENT_
  365.         pdeltat(&r1->ps_utime, &r0->ps_utime);
  366. # else /* _SEQUENT_ */
  367. #  ifndef POSIX
  368.         pdtimet(es->tms_utime, bs->tms_utime);
  369. #  else /* POSIX */
  370.         pdtimet(es->tms_utime, bs->tms_utime);
  371. #  endif /* POSIX */
  372. # endif /* _SEQUENT_ */
  373. #endif /* BSDTIMES */
  374.         break;
  375.  
  376.         case 'S':        /* system CPU time used */
  377. #ifdef BSDTIMES
  378.         pdeltat(&r1->ru_stime, &r0->ru_stime);
  379. #else
  380. # ifdef _SEQUENT_
  381.         pdeltat(&r1->ps_stime, &r0->ps_stime);
  382. # else /* _SEQUENT_ */
  383. #  ifndef POSIX
  384.         pdtimet(es->tms_stime, bs->tms_stime);
  385. #  else /* POSIX */
  386.         pdtimet(es->tms_stime, bs->tms_stime);
  387. #  endif /* POSIX */
  388. # endif /* _SEQUENT_ */
  389. #endif /* BSDTIMES */
  390.         break;
  391.  
  392.         case 'E':        /* elapsed (wall-clock) time */
  393. #ifdef BSDTIMES
  394.         pcsecs((long) ms);
  395. #else /* BSDTIMES */
  396.         pcsecs(ms);
  397. #endif /* BSDTIMES */
  398.         break;
  399.  
  400.         case 'P':        /* percent time spent running */
  401.         /* check if the process did not run */
  402.         i = (ms == 0) ? 0 : (t * 1000 / ms);
  403.         xprintf("%ld.%01ld%%", i / 10, i % 10);    /* nn.n% */
  404.         break;
  405.  
  406. #ifdef BSDTIMES
  407.         case 'W':        /* number of swaps */
  408.         i = r1->ru_nswap - r0->ru_nswap;
  409.         xprintf("%ld", i);
  410.         break;
  411.  
  412.         case 'X':        /* (average) shared text size */
  413.         xprintf("%ld", t == 0 ? 0L :
  414.             IADJUST(r1->ru_ixrss - r0->ru_ixrss) / t);
  415.         break;
  416.  
  417.         case 'D':        /* (average) unshared data size */
  418.         xprintf("%ld", t == 0 ? 0L :
  419.             IADJUST(r1->ru_idrss + r1->ru_isrss -
  420.                 (r0->ru_idrss + r0->ru_isrss)) / t);
  421.         break;
  422.  
  423.         case 'K':        /* (average) total data memory used  */
  424.         xprintf("%ld", t == 0 ? 0L :
  425.             IADJUST((r1->ru_ixrss + r1->ru_isrss + r1->ru_idrss) -
  426.                (r0->ru_ixrss + r0->ru_idrss + r0->ru_isrss)) / t);
  427.         break;
  428.  
  429.         case 'M':        /* max. Resident Set Size */
  430. #ifdef sun
  431. # ifdef notdef
  432.         xprintf("%ld", r1->ru_maxrss * 1024L/(long) getpagesize());
  433. # endif
  434.         xprintf("%ld", pagetok(r1->ru_maxrss));
  435. #else
  436.         xprintf("%ld", r1->ru_maxrss / 2L);
  437. #endif                /* sun */
  438.         break;
  439.  
  440.         case 'F':        /* page faults */
  441.         xprintf("%ld", r1->ru_majflt - r0->ru_majflt);
  442.         break;
  443.  
  444.         case 'R':        /* page reclaims */
  445.         xprintf("%ld", r1->ru_minflt - r0->ru_minflt);
  446.         break;
  447.  
  448.         case 'I':        /* FS blocks in */
  449.         xprintf("%ld", r1->ru_inblock - r0->ru_inblock);
  450.         break;
  451.  
  452.         case 'O':        /* FS blocks out */
  453.         xprintf("%ld", r1->ru_oublock - r0->ru_oublock);
  454.         break;
  455.  
  456.         case 'r':        /* PWP: socket messages recieved */
  457.         xprintf("%ld", r1->ru_msgrcv - r0->ru_msgrcv);
  458.         break;
  459.  
  460.         case 's':        /* PWP: socket messages sent */
  461.         xprintf("%ld", r1->ru_msgsnd - r0->ru_msgsnd);
  462.         break;
  463.  
  464.         case 'k':        /* PWP: signals received */
  465.         xprintf("%ld", r1->ru_nsignals - r0->ru_nsignals);
  466.         break;
  467.  
  468.         case 'w':        /* PWP: voluntary context switches (waits) */
  469.         xprintf("%ld", r1->ru_nvcsw - r0->ru_nvcsw);
  470.         break;
  471.  
  472.         case 'c':        /* PWP: involuntary context switches */
  473.         xprintf("%ld", r1->ru_nivcsw - r0->ru_nivcsw);
  474.         break;
  475. #else /* BSDTIMES */
  476. # ifdef _SEQUENT_
  477.         case 'W':        /* number of swaps */
  478.         i = r1->ps_swap - r0->ps_swap;
  479.         xprintf("%ld", i);
  480.         break;
  481.  
  482.         case 'M':
  483.         xprintf("%ld", r1->ps_maxrss / 2);
  484.         break;
  485.  
  486.         case 'F':
  487.         xprintf("%ld", r1->ps_pagein - r0->ps_pagein);
  488.         break;
  489.  
  490.         case 'R':
  491.         xprintf("%ld", r1->ps_reclaim - r0->ps_reclaim);
  492.         break;
  493.  
  494.         case 'I':
  495.         xprintf("%ld", r1->ps_bread - r0->ps_bread);
  496.         break;
  497.  
  498.         case 'O':
  499.         xprintf("%ld", r1->ps_bwrite - r0->ps_bwrite);
  500.         break;
  501.  
  502.         case 'k':
  503.         xprintf("%ld", r1->ps_signal - r0->ps_signal);
  504.         break;
  505.  
  506.         case 'w':
  507.         xprintf("%ld", r1->ps_volcsw - r0->ps_volcsw);
  508.         break;
  509.  
  510.         case 'c':
  511.         xprintf("%ld", r1->ps_involcsw - r0->ps_involcsw);
  512.         break;
  513.  
  514.         case 'Z':
  515.         xprintf("%ld", r1->ps_zerofill - r0->ps_zerofill);
  516.         break;
  517.  
  518.         case 'i':
  519.         xprintf("%ld", r1->ps_pffincr - r0->ps_pffincr);
  520.         break;
  521.  
  522.         case 'd':
  523.         xprintf("%ld", r1->ps_pffdecr - r0->ps_pffdecr);
  524.         break;
  525.  
  526.         case 'Y':
  527.         xprintf("%ld", r1->ps_syscall - r0->ps_syscall);
  528.         break;
  529.  
  530.         case 'l':
  531.         xprintf("%ld", r1->ps_lread - r0->ps_lread);
  532.         break;
  533.  
  534.         case 'm':
  535.         xprintf("%ld", r1->ps_lwrite - r0->ps_lwrite);
  536.         break;
  537.  
  538.         case 'p':
  539.         xprintf("%ld", r1->ps_phread - r0->ps_phread);
  540.         break;
  541.  
  542.         case 'q':
  543.         xprintf("%ld", r1->ps_phwrite - r0->ps_phwrite);
  544.         break;
  545. # endif    /* _SEQUENT_ */
  546. #endif /* BSDTIMES */
  547.         default:
  548.         break;
  549.         }
  550.     xputchar('\n');
  551. }
  552.  
  553. #if defined(BSDTIMES) || defined(_SEQUENT_)
  554. static void
  555. pdeltat(t1, t0)
  556.     timeval_t *t1, *t0;
  557. {
  558.     timeval_t td;
  559.  
  560.     tvsub(&td, t1, t0);
  561.     xprintf("%ld.%03ld", td.tv_sec, td.tv_usec / 1000L);
  562. }
  563.  
  564. void
  565. tvadd(tsum, t0)
  566.     timeval_t *tsum, *t0;
  567. {
  568.  
  569.     tsum->tv_sec += t0->tv_sec;
  570.     tsum->tv_usec += t0->tv_usec;
  571.     if (tsum->tv_usec > 1000000)
  572.     tsum->tv_sec++, tsum->tv_usec -= 1000000;
  573. }
  574.  
  575. void
  576. tvsub(tdiff, t1, t0)
  577.     timeval_t *tdiff, *t1, *t0;
  578. {
  579.  
  580.     tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
  581.     tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
  582.     if (tdiff->tv_usec < 0)
  583.     tdiff->tv_sec--, tdiff->tv_usec += 1000000;
  584. }
  585.  
  586. #else /* !BSDTIMES && !_SEQUENT_ */
  587. static void
  588. pdtimet(eval, bval)
  589. #ifndef POSIX
  590.     time_t  eval, bval;
  591.  
  592. #else /* POSIX */
  593.     clock_t eval, bval;
  594.  
  595. #endif /* POSIX */
  596. {
  597. #ifndef POSIX
  598.     time_t  val;
  599.  
  600. #else /* POSIX */
  601.     clock_t val;
  602.  
  603. #endif /* POSIX */
  604.  
  605. #ifndef POSIX
  606.     val = (eval - bval) * 100 / HZ;
  607. #else /* POSIX */
  608.     val = (eval - bval) * 100 / CLK_TCK;
  609. #endif /* POSIX */
  610.  
  611.     xprintf("%ld.%02ld", val / 100, val - (val / 100 * 100));
  612. }
  613. #endif /* BSDTIMES || _SEQUENT_ */
  614.